From 7a542c51b71c614a152f9e30f6fa429bb7317c45 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 11 Sep 2014 07:35:01 -0700 Subject: [PATCH] Don't print `Running` for commands that aren't run Also print the commands only right before they're actually run. Closes #215 --- src/cargo/ops/cargo_rustc/job.rs | 17 +++++++++-- src/cargo/ops/cargo_rustc/job_queue.rs | 3 ++ src/cargo/ops/cargo_rustc/mod.rs | 42 ++++++++++++-------------- tests/test_cargo_bench.rs | 10 ++---- tests/test_cargo_compile.rs | 11 ++++--- tests/test_cargo_cross_compile.rs | 2 +- tests/test_cargo_profiles.rs | 8 +++-- tests/test_cargo_test.rs | 2 +- 8 files changed, 54 insertions(+), 41 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/job.rs b/src/cargo/ops/cargo_rustc/job.rs index fa11bb095..6493772f1 100644 --- a/src/cargo/ops/cargo_rustc/job.rs +++ b/src/cargo/ops/cargo_rustc/job.rs @@ -1,14 +1,18 @@ +use std::io::IoResult; + +use core::MultiShell; use util::{CargoResult, Fresh, Dirty, Freshness}; -pub struct Job { dirty: Work, fresh: Work } +pub struct Job { dirty: Work, fresh: Work, desc: String } pub type Work = proc():Send -> CargoResult<()>; impl Job { /// Create a new job representing a unit of work. pub fn new(dirty: proc():Send -> CargoResult<()>, - fresh: proc():Send -> CargoResult<()>) -> Job { - Job { dirty: dirty, fresh: fresh } + fresh: proc():Send -> CargoResult<()>, + desc: String) -> Job { + Job { dirty: dirty, fresh: fresh, desc: desc } } /// Consumes this job by running it, returning the result of the @@ -19,4 +23,11 @@ impl Job { Dirty => (self.dirty)(), } } + + pub fn describe(&self, shell: &mut MultiShell) -> IoResult<()> { + if self.desc.len() > 0 { + try!(shell.status("Running", self.desc.as_slice())); + } + Ok(()) + } } diff --git a/src/cargo/ops/cargo_rustc/job_queue.rs b/src/cargo/ops/cargo_rustc/job_queue.rs index bc5d21718..7c32426c7 100644 --- a/src/cargo/ops/cargo_rustc/job_queue.rs +++ b/src/cargo/ops/cargo_rustc/job_queue.rs @@ -168,6 +168,9 @@ impl<'a, 'b> JobQueue<'a, 'b> { let fresh = job_freshness.combine(fresh); let my_tx = self.tx.clone(); let id = id.clone(); + if fresh == Dirty { + try!(config.shell().verbose(|shell| job.describe(shell))); + } self.pool.execute(proc() { my_tx.send((id, stage, fresh, job.run(fresh))); }); diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index cc8263493..dc917bdd1 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -109,10 +109,10 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package, // Prepare the fingerprint directory as the first step of building a package let (target1, target2) = fingerprint::prepare_init(cx, pkg, KindTarget); - let mut init = vec![(Job::new(target1, target2), Fresh)]; + let mut init = vec![(Job::new(target1, target2, String::new()), Fresh)]; if cx.config.target().is_some() { let (plugin1, plugin2) = fingerprint::prepare_init(cx, pkg, KindPlugin); - init.push((Job::new(plugin1, plugin2), Fresh)); + init.push((Job::new(plugin1, plugin2, String::new()), Fresh)); } jobs.enqueue(pkg, StageStart, init); @@ -125,11 +125,17 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package, } let (freshness, dirty, fresh) = try!(fingerprint::prepare_build_cmd(cx, pkg)); + let desc = match build_cmds.len() { + 0 => String::new(), + 1 => pkg.get_manifest().get_build()[0].to_string(), + _ => format!("custom build commands"), + }; let dirty = proc() { for cmd in build_cmds.move_iter() { try!(cmd()) } dirty() }; - jobs.enqueue(pkg, StageCustomBuild, vec![(Job::new(dirty, fresh), freshness)]); + jobs.enqueue(pkg, StageCustomBuild, vec![(Job::new(dirty, fresh, desc), + freshness)]); // After the custom command has run, execute rustc for all targets of our // package. @@ -139,19 +145,20 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package, let (mut libs, mut bins) = (Vec::new(), Vec::new()); for &target in targets.iter() { let work = if target.get_profile().is_doc() { - vec![(try!(rustdoc(pkg, target, cx)), KindTarget)] + let (rustdoc, desc) = try!(rustdoc(pkg, target, cx)); + vec![(rustdoc, KindTarget, desc)] } else { let req = cx.get_requirement(pkg, target); try!(rustc(pkg, target, cx, req)) }; let dst = if target.is_lib() {&mut libs} else {&mut bins}; - for (work, kind) in work.move_iter() { + for (work, kind, desc) in work.move_iter() { let (freshness, dirty, fresh) = try!(fingerprint::prepare_target(cx, pkg, target, kind)); let dirty = proc() { try!(work()); dirty() }; - dst.push((Job::new(dirty, fresh), freshness)); + dst.push((Job::new(dirty, fresh, desc), freshness)); } } jobs.enqueue(pkg, StageLibraries, libs); @@ -209,7 +216,7 @@ fn compile_custom(pkg: &Package, cmd: &str, fn rustc(package: &Package, target: &Target, cx: &mut Context, req: PlatformRequirement) - -> CargoResult >{ + -> CargoResult >{ let crate_types = target.rustc_crate_types(); let root = package.get_root(); @@ -219,15 +226,9 @@ fn rustc(package: &Package, target: &Target, let primary = cx.primary; let rustcs = try!(prepare_rustc(package, target, crate_types, cx, req)); - let _ = cx.config.shell().verbose(|shell| { - for &(ref rustc, _) in rustcs.iter() { - try!(shell.status("Running", rustc.to_string())); - } - Ok(()) - }); - Ok(rustcs.move_iter().map(|(rustc, kind)| { let name = package.get_name().to_string(); + let desc = rustc.to_string(); (proc() { if primary { @@ -243,7 +244,7 @@ fn rustc(package: &Package, target: &Target, })) } Ok(()) - }, kind) + }, kind, desc) }).collect()) } @@ -272,7 +273,7 @@ fn prepare_rustc(package: &Package, target: &Target, crate_types: Vec<&str>, fn rustdoc(package: &Package, target: &Target, - cx: &mut Context) -> CargoResult { + cx: &mut Context) -> CargoResult<(Work, String)> { let kind = KindTarget; let pkg_root = package.get_root(); let cx_root = cx.layout(kind).proxy().dest().join("doc"); @@ -284,13 +285,10 @@ fn rustdoc(package: &Package, target: &Target, log!(5, "commands={}", rustdoc); - let _ = cx.config.shell().verbose(|shell| { - shell.status("Running", rustdoc.to_string()) - }); - let primary = cx.primary; let name = package.get_name().to_string(); - Ok(proc() { + let desc = rustdoc.to_string(); + Ok((proc() { if primary { try!(rustdoc.exec().chain_error(|| { human(format!("Could not document `{}`.", name)) @@ -309,7 +307,7 @@ fn rustdoc(package: &Package, target: &Target, })) } Ok(()) - }) + }, desc)) } fn build_base_args(cx: &Context, mut cmd: ProcessBuilder, diff --git a/tests/test_cargo_bench.rs b/tests/test_cargo_bench.rs index ed878ef28..bd171b94d 100644 --- a/tests/test_cargo_bench.rs +++ b/tests/test_cargo_bench.rs @@ -61,8 +61,8 @@ test!(cargo_bench_verbose { assert_that(p.cargo_process("bench").arg("-v").arg("hello"), execs().with_stdout(format!("\ -{running} `rustc src[..]foo.rs [..]` {compiling} foo v0.5.0 ({url}) +{running} `rustc src[..]foo.rs [..]` {running} `[..]target[..]release[..]foo-[..] hello --bench` running 1 test @@ -654,12 +654,12 @@ test!(bench_dylib { assert_that(p.cargo_process("bench").arg("-v"), execs().with_status(0) .with_stdout(format!("\ +{compiling} bar v0.0.1 ({dir}) {running} [..] +{compiling} foo v0.0.1 ({dir}) {running} [..] {running} [..] {running} [..] -{compiling} bar v0.0.1 ({dir}) -{compiling} foo v0.0.1 ({dir}) {running} [..]target[..]release[..]bench-[..] running 1 test @@ -681,10 +681,6 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured assert_that(p.process(cargo_dir().join("cargo")).arg("bench").arg("-v"), execs().with_status(0) .with_stdout(format!("\ -{running} [..] -{running} [..] -{running} [..] -{running} [..] {fresh} bar v0.0.1 ({dir}) {fresh} foo v0.0.1 ({dir}) {running} [..]target[..]release[..]bench-[..] diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 976dab449..af390469d 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -1158,6 +1158,7 @@ test!(verbose_build { .file("src/lib.rs", ""); assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0).with_stdout(format!("\ +{compiling} test v0.0.0 ({url}) {running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib -g \ -C metadata=[..] \ -C extra-filename=-[..] \ @@ -1165,7 +1166,7 @@ test!(verbose_build { --dep-info [..] \ -L {dir}{sep}target \ -L {dir}{sep}target{sep}deps` -{compiling} test v0.0.0 ({url})\n", +", running = RUNNING, compiling = COMPILING, sep = path::SEP, dir = p.root().display(), url = p.url(), @@ -1185,6 +1186,7 @@ test!(verbose_release_build { .file("src/lib.rs", ""); assert_that(p.cargo_process("build").arg("-v").arg("--release"), execs().with_status(0).with_stdout(format!("\ +{compiling} test v0.0.0 ({url}) {running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \ --opt-level 3 \ --cfg ndebug \ @@ -1194,7 +1196,7 @@ test!(verbose_release_build { --dep-info [..] \ -L {dir}{sep}target{sep}release \ -L {dir}{sep}target{sep}release{sep}deps` -{compiling} test v0.0.0 ({url})\n", +", running = RUNNING, compiling = COMPILING, sep = path::SEP, dir = p.root().display(), url = p.url(), @@ -1229,6 +1231,7 @@ test!(verbose_release_build_deps { .file("foo/src/lib.rs", ""); assert_that(p.cargo_process("build").arg("-v").arg("--release"), execs().with_status(0).with_stdout(format!("\ +{compiling} foo v0.0.0 ({url}) {running} `rustc {dir}{sep}foo{sep}src{sep}lib.rs --crate-name foo \ --crate-type dylib --crate-type rlib \ --opt-level 3 \ @@ -1239,6 +1242,7 @@ test!(verbose_release_build_deps { --dep-info [..] \ -L {dir}{sep}target{sep}release{sep}deps \ -L {dir}{sep}target{sep}release{sep}deps` +{compiling} test v0.0.0 ({url}) {running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \ --opt-level 3 \ --cfg ndebug \ @@ -1251,8 +1255,7 @@ test!(verbose_release_build_deps { --extern foo={dir}{sep}target{sep}release{sep}deps/\ {prefix}foo-[..]{suffix} \ --extern foo={dir}{sep}target{sep}release{sep}deps/libfoo-[..].rlib` -{compiling} foo v0.0.0 ({url}) -{compiling} test v0.0.0 ({url})\n", +", running = RUNNING, compiling = COMPILING, dir = p.root().display(), diff --git a/tests/test_cargo_cross_compile.rs b/tests/test_cargo_cross_compile.rs index 13c1c6663..1f06e35d0 100644 --- a/tests/test_cargo_cross_compile.rs +++ b/tests/test_cargo_cross_compile.rs @@ -295,6 +295,7 @@ test!(linker_and_ar { .arg("-v"), execs().with_status(101) .with_stdout(format!("\ +{compiling} foo v0.5.0 ({url}) {running} `rustc src/foo.rs --crate-name foo --crate-type bin -g \ --out-dir {dir}{sep}target{sep}{target} \ --dep-info [..] \ @@ -302,7 +303,6 @@ test!(linker_and_ar { -C ar=my-ar-tool -C linker=my-linker-tool \ -L {dir}{sep}target{sep}{target} \ -L {dir}{sep}target{sep}{target}{sep}deps` -{compiling} foo v0.5.0 ({url}) ", running = RUNNING, compiling = COMPILING, diff --git a/tests/test_cargo_profiles.rs b/tests/test_cargo_profiles.rs index e51ad49c7..c85b43db0 100644 --- a/tests/test_cargo_profiles.rs +++ b/tests/test_cargo_profiles.rs @@ -25,6 +25,7 @@ test!(profile_overrides { .file("src/lib.rs", ""); assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0).with_stdout(format!("\ +{compiling} test v0.0.0 ({url}) {running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \ --opt-level 1 \ --cfg ndebug \ @@ -34,7 +35,7 @@ test!(profile_overrides { --dep-info [..] \ -L {dir}{sep}target \ -L {dir}{sep}target{sep}deps` -{compiling} test v0.0.0 ({url})\n", +", running = RUNNING, compiling = COMPILING, sep = path::SEP, dir = p.root().display(), url = p.url(), @@ -77,6 +78,7 @@ test!(top_level_overrides_deps { .file("foo/src/lib.rs", ""); assert_that(p.cargo_process("build").arg("-v").arg("--release"), execs().with_status(0).with_stdout(format!("\ +{compiling} foo v0.0.0 ({url}) {running} `rustc {dir}{sep}foo{sep}src{sep}lib.rs --crate-name foo \ --crate-type dylib --crate-type rlib \ --opt-level 1 \ @@ -87,6 +89,7 @@ test!(top_level_overrides_deps { --dep-info [..] \ -L {dir}{sep}target{sep}release{sep}deps \ -L {dir}{sep}target{sep}release{sep}deps` +{compiling} test v0.0.0 ({url}) {running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \ --opt-level 1 \ -g \ @@ -99,8 +102,7 @@ test!(top_level_overrides_deps { --extern foo={dir}{sep}target{sep}release{sep}deps/\ {prefix}foo-[..]{suffix} \ --extern foo={dir}{sep}target{sep}release{sep}deps/libfoo-[..].rlib` -{compiling} foo v0.0.0 ({url}) -{compiling} test v0.0.0 ({url})\n", +", running = RUNNING, compiling = COMPILING, dir = p.root().display(), diff --git a/tests/test_cargo_test.rs b/tests/test_cargo_test.rs index a7685e085..0b29040cc 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test_cargo_test.rs @@ -58,8 +58,8 @@ test!(cargo_test_verbose { assert_that(p.cargo_process("test").arg("-v").arg("hello"), execs().with_stdout(format!("\ -{running} `rustc src[..]foo.rs [..]` {compiling} foo v0.5.0 ({url}) +{running} `rustc src[..]foo.rs [..]` {running} `[..]target[..]foo-[..] hello` running 1 test -- 2.30.2